package humanMirror.controller;

import java.util.HashMap;
import java.util.Map;

import humanMirror.controller.actions.Action;
import humanMirror.controller.actions.DefaultAction;
import humanMirror.controller.actions.LogOutAction;
import humanMirror.controller.actions.LoginCheckAction;
import humanMirror.controller.actions.QuizAction;
import humanMirror.controller.actions.RegisterAction;


public class ActionFactory {
	protected Map<String, Class<?>> map = defaultMap();

	public Action create(String actionName) {
		Class<?> actionClass = (Class<?>) map.get(actionName);
		Action actionInstance = null;

		if (actionClass == null){
			return actionInstance = new DefaultAction();//class.newInstance
		}else{
			try {
				actionInstance = (Action) actionClass.newInstance();
			} catch (Exception e) {
				e.printStackTrace();
			}	
		}
		return actionInstance;
	}

	protected Map<String, Class<?>> defaultMap() {
		Map<String, Class<?>> map = new HashMap<String, Class<?>>();
		map.put("loginCheckAction", LoginCheckAction.class);
		map.put("logoutAction", LogOutAction.class);
		map.put("quizAction", QuizAction.class);
		map.put("defaultAction", DefaultAction.class);
		map.put("registerAction", RegisterAction.class);
		return map;
	}
}
